import  {array_methods } from "./arrayMethodsReactivify"
function defineReactive (data, key, val, enumerable) {
    if (arguments.length == 2) {
        val = data[key]
    }
    reactivify(val)
    Object.defineProperty(data, key, {
        enumerable: enumerable,
        configurable: true,
        get () {
            console.log(`你正在读取属性${key}，值为${val}`)
            return val
        },
        set (newValue) {
            if (val == newValue) {
                return
            }
            console.log('你正在修改属性',key,'的值：',newValue)
            val = newValue
            reactivify(val)
        }
    })
}
export default function reactivify(val) {
    if (typeof(val) == 'object' && val != null && !Array.isArray(val)) {
        for (const key in val) {
            defineReactive(val, key, val[key], true)
        }
    } else if (Array.isArray(val)) {
        val.__proto__ = array_methods
        for (let i = 0; i < val.length; i++) {
            reactivify(val[i])
        }
    }
}

